home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / scalarRandom.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  1.6 KB  |  51 lines

  1. //
  2. //  ====================== scalarRandom ======================
  3. //
  4. //  Two routines for setting the (scalar) attributes of particles
  5. //  to random values.  
  6.  
  7. global proc scalarRandom( string $attr, float $value, float $random )
  8. //
  9. // Description: 
  10. //   Sets the specified attribute of all particles in a selected component to 
  11. // a random value uniformly distributed with a mean of $value and a distritbution of $random.
  12. // Thus, the value varies from $value - $random/2 to $value + $random/2.
  13. // This script assumes the component is already selected.
  14. // Does not check that the object or attribute is valid.
  15. // Use at your own risk.
  16. //
  17. // Usage:
  18. //   select -r particle1.pt[0:10];
  19. //   scalarRandom("myParticle", "radiusPP", 1.0, 3.0 );
  20. {
  21.     setParticleAttr -at $attr -fv $value;
  22.     setParticleAttr -at $attr -relative true -rf ($random/2);
  23. }
  24.  
  25.  
  26. global proc scalarRandomObject( string $pObj, string $attr, float $value, float $random )
  27. //
  28. // Description:
  29. //  Same as scalarRandom, but simply operates on all particles in the
  30. // given object. Does not check that the object or attribute is valid.
  31. // Use at your own risk.
  32. //
  33. // Usage:
  34. //   scalarRandomObject("myParticle", "radiusPP", 1.0, 3.0 );
  35. {
  36.     if (catch( `ls pObj`)) return;
  37.  
  38.     // if ("particle" != nodeType( $pObj ) return;
  39.  
  40.     int $count = `getAttr ($pObj+".count")`;
  41.     
  42.     // select a component consisting of all the particles.
  43.     //
  44.     string $selectCmd = "select -r " + $pObj + ".pt[0:" + ($count-1) + "]";
  45.     eval($selectCmd);
  46.  
  47.     // now randomize the attribute
  48.     //
  49.     scalarRandom( $attr, $value, $random );
  50. }
  51.